package features.word_counter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import dictionary.Dictionary;



public abstract class WordCounter {
	
	private Dictionary dict;
	
	
	public WordCounter(Dictionary dict) {
		this.dict = dict;
	}
	
	public List<String> getAllWords() {
		return dict.getAllWords();
	}
	
	public String getStemmedWord(String word) { 
		return dict.getWordAttributeEquivalent(word);
	}
	
	
	public boolean isValidWord(String word) {
		return dict.isValidWord(word);
	}
	
	public int getWordIdx(String word) {
		return dict.getWordIdx(word);
	}
	
	public double getInverseFrequency(String word) {
		return dict.getIdf(word);
	}
	
	public HashMap<String,Double> getWordCount(String line) {
		HashMap<String,Double> res = new HashMap<String,Double>();
		ArrayList<String> words = getAllWords(line);
		for ( String word : words ) {
			String stemmed_word = getStemmedWord(word);
			if ( stemmed_word == null ) continue;
			Double d = res.get(stemmed_word);
			if ( d == null ) d = 0.0;
			++d;
			res.put(stemmed_word, d);
		}
		return res;
	}

	public abstract ArrayList<String> getAllWords(String line);

	public int getNumWords() {
		return dict.getAllWords().size();
	}
	
}
